package com.atwork.wuhua.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.atwork.wuhua.R;
import com.atwork.wuhua.bean.MyWarBean;
import com.atwork.wuhua.ui.activity.MyWarActivity;
import com.atwork.wuhua.wrideg.StarBar;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

public class MyWarAdapter extends BaseQuickAdapter<MyWarBean.DataBean, BaseViewHolder> {
    private String mType;

    public MyWarAdapter(String mType, int layoutResId, @Nullable List<MyWarBean.DataBean> data) {
        super(layoutResId, data);
        this.mType = mType;
    }

    @Override
    protected void convert(BaseViewHolder helper, MyWarBean.DataBean item) {
        helper.addOnClickListener(R.id.tv_evaluate).addOnClickListener(R.id.lly_left);
        helper.setText(R.id.tv_time, "时间：" + item.getDate() + " " + item.getTime())
                .setText(R.id.tv_address, "场地:" + item.getSite_name());
        ((StarBar) helper.getView(R.id.starBar)).setIsOnTouch(false);
        ((StarBar) helper.getView(R.id.starBar)).setStarMark(Float.parseFloat(item.getStarts()));
        if (mType.equals(MyWarActivity.MYSUB)) {
            helper.getView(R.id.tv_name).setVisibility(View.GONE);
            if (item.getState_id().equals("1")) {
                if (item.isCan_cancel()) {
                    ((TextView) helper.getView(R.id.tv_evaluate)).setBackgroundResource(R.drawable.shape_green_13r);
                    ((TextView) helper.getView(R.id.tv_evaluate)).setText("取消预约");
                } else {
                    if (item.isCan_evaluate()) {
                        ((TextView) helper.getView(R.id.tv_evaluate)).setBackgroundResource(R.drawable.shape_evaluate_yes);
                        ((TextView) helper.getView(R.id.tv_evaluate)).setText("去评价");
                    } else {
                        ((TextView) helper.getView(R.id.tv_evaluate)).setBackgroundResource(R.drawable.shape_evaluate_yes);
                        ((TextView) helper.getView(R.id.tv_evaluate)).setText(item.getState());
                    }
                }
            } else if (item.getState_id().equals("2")) {
                ((TextView) helper.getView(R.id.tv_evaluate)).setBackgroundResource(R.drawable.shape_evaluate_no);
                ((TextView) helper.getView(R.id.tv_evaluate)).setText("已评价");
            } else if (item.getState_id().equals("3")) {
                ((TextView) helper.getView(R.id.tv_evaluate)).setBackgroundResource(R.drawable.shape_evaluate_no);
                ((TextView) helper.getView(R.id.tv_evaluate)).setText("已取消");
            }

        } else {
            helper.getView(R.id.tv_name).setVisibility(View.VISIBLE);
            helper.setText(R.id.tv_name, "发起人：" + item.getNickname());
            if (item.getState_id().equals("1")) {
                if (item.isCan_cancel()) {
                    ((TextView) helper.getView(R.id.tv_evaluate)).setBackgroundResource(R.drawable.shape_green_13r);
                    ((TextView) helper.getView(R.id.tv_evaluate)).setText("取消约战");
                } else {
                    ((TextView) helper.getView(R.id.tv_evaluate)).setBackgroundResource(R.drawable.shape_evaluate_yes);
                    ((TextView) helper.getView(R.id.tv_evaluate)).setText("查看");

                }
            }
        }
    }
}
